import sys
sys.path.append("../utils")
config_path = "./config.cfg"

import ConfigParser
import time
import datetime as dt

import matplotlib.pyplot as plt
import numpy as np

import get_data
import pls_model


def get_model():
    start_time = time.time()
    config = ConfigParser.ConfigParser()
    config.read(config_path)
    turbines = config.get('options', 'turbines').split(',')
    bin_path = config.get("options", "bin_path")
    h5file = config.get("options", "h5file")
    f_h5 = bin_path + h5file
    data_sets = get_data.from_turbines(turbines, f_h5)


    key_list = data_sets[0].dtype.names
    y_para = "GearBearTempAvg"
    para_sets = pls_model.get_temp_set(key_list, y_para)

    zero_days = [dt.datetime(2011,1,1), dt.datetime(2011,2,1),
            dt.datetime(2011,3,1), dt.datetime(2011,4,1),
            dt.datetime(2011,5,1), dt.datetime(2011,6,1)]

    para_set = para_sets[0]
    day_zero = zero_days[0]
    data = data_sets[1]
    num_of_model_samples = 1500
    pred = 5


    out = pls_model.set_up(data, 10, para_set,
            stop_day=day_zero,
            length_of_model_period=num_of_model_samples,
            pred_days=pred)

    print out["b"]

    print "Done in:",
    print (time.time() - start_time)

    return

def main():
    get_model()
    return

if __name__=='__main__':
    main()
